<?php 

namespace Acme\UserBundle\Form;
 
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;

class UserInfoType extends AbstractType
{
    public function buildForm(FormBuilder $builder, array $options)
    {
    	if ($options['category_name'] == 'student' || $options['category_name'] == 'teacher') {
    		$builder->add('name', 'text', array('label' => '真实姓名'));
    		$builder->add('gender', 'gender');
    		$builder->add('birth', 'date', array('label' => '生日', 'widget' => 'single_text', 'format' => 'yyyy-MM-dd',));  // , 'read_only' => true
    		
    		if ($options['category_name'] == 'student') {
    			$builder->add('stuNum', 'text', array('label' => '学号'));
    		}
    		
    		$builder->add('university', 'universitySelector');
    		$builder->add('phone', 'text', array('label' => '手机'));
    		$builder->add('qq', 'text', array('label' => 'QQ'));
    		$builder->add('idCard', 'text', array('label' => '身份证号'));
    	}
    	
    	if ($options['category_name'] == 'university-admin') {
    		$builder->add('university', 'universitySelector');
    	}
    	
    	if ($options['build_for'] == 'regist') {
    		$builder->add('user', new UserType());
    	}
    }
    
    // the name of the class that holds the underlying data(for use of function createForm)
    public function getDefaultOptions(array $options)
    {
    	if ($options['build_for'] == 'regist') {
    		return array(
    				'build_for' => $options['build_for'],
    				'data_class' => 'Acme\UserBundle\Entity\CmUserInfo',
    				'validation_groups' => array('regist_default', 'regist_' . $options['category_name']),
    				'category_name' => $options['category_name'],
    				'required' => false,
    		);
    	} elseif ($options['build_for'] == 'edit') {
    		return array(
    				'build_for' => $options['build_for'],
   					'data_class' => 'Acme\UserBundle\Entity\CmUserInfo',
    				'category_name' => $options['category_name'],
   					'required' => false,
    		);
    	}
    }
    
    // note that the getName() method should return a unique identifier for this form "type"
    public function getName()
    {
    	return 'user_info';
    }
}